# SPDX-FileCopyrightText: Copyright (c) {{cookiecutter.year}} {{cookiecutter.copyright_holder}}.
# SPDX-License-Identifier: Apache-2.0

# These tests run the application, so they need the SDK. Register SDK-free
# tests in the application's top-level CMakeLists.txt instead.
{%- set slug = cookiecutter.project_slug %}
{%- if ',' in cookiecutter.language %}
# cpp/ and python/ both add this folder. Register the tests of the
# implementation whose folder added it.
get_directory_property(implementation PARENT_DIRECTORY)
get_filename_component(implementation "${implementation}" NAME)
if(implementation STREQUAL "cpp")
  add_test(NAME {{ slug }}_cpp_pipeline
    COMMAND {{ slug }} --count 10 --period-ms 1)
  add_test(NAME {{ slug }}_cpp_rejects_zero_count
    COMMAND {{ slug }} --count 0)
else()
  find_package(Python3 3.12 REQUIRED COMPONENTS Interpreter)
  set(script "${CMAKE_CURRENT_SOURCE_DIR}/../python/{{ slug }}.py")
  add_test(NAME {{ slug }}_python_pipeline
    COMMAND ${Python3_EXECUTABLE} ${script} --count 10 --period-ms 1)
  add_test(NAME {{ slug }}_python_rejects_zero_count
    COMMAND ${Python3_EXECUTABLE} ${script} --count 0)
endif()
set(prefix "{{ slug }}_${implementation}")
# Match the message, which a missing program or a crash does not print.
set_tests_properties(${prefix}_rejects_zero_count PROPERTIES
  PASS_REGULAR_EXPRESSION "--count and --timeout-seconds must be positive")
set_tests_properties(
  ${prefix}_pipeline ${prefix}_rejects_zero_count
  PROPERTIES LABELS "{{ slug }}" TIMEOUT 60)
{%- else %}
{%- if cookiecutter.language == 'python' %}
find_package(Python3 3.12 REQUIRED COMPONENTS Interpreter)
set(script "${CMAKE_CURRENT_SOURCE_DIR}/../python/{{ slug }}.py")
add_test(NAME {{ slug }}_pipeline
  COMMAND ${Python3_EXECUTABLE} ${script} --count 10 --period-ms 1)
add_test(NAME {{ slug }}_rejects_zero_count
  COMMAND ${Python3_EXECUTABLE} ${script} --count 0)
{%- else %}
add_test(NAME {{ slug }}_pipeline
  COMMAND {{ slug }} --count 10 --period-ms 1)
add_test(NAME {{ slug }}_rejects_zero_count
  COMMAND {{ slug }} --count 0)
{%- endif %}
# Match the message, which a missing program or a crash does not print.
set_tests_properties({{ slug }}_rejects_zero_count PROPERTIES
  PASS_REGULAR_EXPRESSION "--count and --timeout-seconds must be positive")
set_tests_properties(
  {{ slug }}_pipeline {{ slug }}_rejects_zero_count
  PROPERTIES LABELS "{{ slug }}" TIMEOUT 60)
{%- endif %}
